package com.teleca.jamendo.dialog;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;

import android.app.Activity;
import android.content.Intent;

import com.teleca.jamendo.api.JamendoGet2Api;
import com.teleca.jamendo.api.WSError;
import com.teleca.jamendo.api.impl.JamendoGet2ApiImpl;
import com.teleca.jamendo.mode.Album;
import com.teleca.jamendo.ui.activity.StarredAlbumsActivity;

public class StarredAlbumLoading extends LoadingDialog<String, List<Album>> {

	public StarredAlbumLoading(Activity activity, int loadingMsg, int failMsg) {
		super(activity, loadingMsg, failMsg);
	}

	@Override
	public List<Album> doInBackground(String... params) {
		String user = params[0];
		JamendoGet2Api service = new JamendoGet2ApiImpl();
		try {
			return service.getUserStarredAlbums(user);
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (WSError e) {
			publishProgress(e);
			cancel(true);
		}
		return null;
	}

	@Override
	public void doStuffWithResult(List<Album> result) {
		Intent intent = new Intent(mActivity, StarredAlbumsActivity.class);
		ArrayList<Album> list = new ArrayList<Album>();
		for (Album a : result)
			list.add(a);
		intent.putExtra("albums", list);
		mActivity.startActivity(intent);
	}

}
